<?php
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
include(APP_ROOT.'include/classes/constants.php');
include('../library/functions.php');
#=======CONSTANTS=======
$ROWSPERPAGE = 10;
#=======================

if(!isset($productID)) {
	$sql = "SELECT auction_id, product_id, starts_timestamp, one_time_24h,"
		." fresh_auction, suspended FROM ".TBL_AUCTIONS ." WHERE closed = 0";
}
else {
	$sql = "SELECT auction_id, product_id, starts_timestamp, one_time_24h,"
		." fresh_auction, suspended FROM ". TBL_AUCTIONS
		." WHERE closed = 0 AND product_id = $productID";
	$prod_info = execute_query('SELECT * FROM '. TBL_PRODUCTS .' WHERE product_id = ?', array($productID));
}

$result = execute_query($sql);
$pagingLink = getPagingLink($sql, $ROWSPERPAGE);
?>
<p>&nbsp;</p>
 <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="text">
   <tr align="center" class="listTableHeader">
	 <td colspan="7" class="text"><form name="form" action="index.php" method="get">
	   <br />
	   Numele produsului&nbsp;
	   <input type="hidden" name="view" id="view" value="search"/>
	   <input type="hidden" name="find" id="find" value="open"/>
       <input type="text" class="box" name="q" id="q" />
	   <input type="submit" class="box" name="submit" id="submit" value="Cauta" />
	 </form></td>
   </tr>
   <tr align="center" class="listTableHeader"> 
     <td>Nume Produs</td>
     <td width="75">Foto</td>
     <td>Data Inceperii</td>
     <td>Actiuni</td>
	 <td>Parametrii</td>
   </tr>
<?php
$page_lo = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (9 * ($_GET['page'] - 1)) : 0;
$page_hi = $page_lo + 9;
$count = count($result);

if($count > 0) {
	if($count < $page_hi) {
		$page_hi = $count;
	}
	for($i = $page_lo; $i < $page_hi; $i++) {
		if ($i%2) {
			$class = 'row1';
		} else {
			$class = 'row2';
		}
		if(!isset($productID)) {
			$prod_info = execute_query('SELECT * FROM '.TBL_PRODUCTS.' WHERE product_id = ?', array($result[$i]['product_id']));
		}
		?>
		<tr class="<?php echo $class; ?>"> 
		   <td width="100"><a href="../product/index.php?view=detail&productId=<?php echo $result[$i]['product_id']; ?>">
				<?php echo $prod_info[0]['product_name']; ?></a></td>
		   <td width="75" align="center"><img src="../../produse/thumb_<?php echo $prod_info[0]['pict1_url']; ?>"/></td>
		   <td align="center">
			<?php echo date("j/n/Y - H:i:s", $result[$i]['starts_timestamp']); ?>
		   </td>
		   <td width="75" align="center">
			<a href="javascript:deleteAuction(<?php echo $result[$i]['auction_id']; ?>, 'open');"><img style="border: 0;" alt="Sterge" title="Sterge" src="../include/delete.png"/></a>
			<?php if($result[$i]['suspended'] == 'N') { ?>
			<a href="javascript:suspendAuction(<?php echo $result[$i]['auction_id'];?>);"><img style="border: 0;" alt="Suspendeaza" title="Suspendeaza" src="../include/suspend.png"/>
			<?php } else { ?>
			<a href="javascript:resumeAuction(<?php echo $result[$i]['auction_id']; ?>);"><img style="border: 0;" alt="Continua" title="Continua" src="../include/resume.png"/>
			<?php } ?>
		   </a></td>
		   <td align="center">
				<?php echo ($result[$i]['one_time_24h'] == 1)?"<img title=\"Limita 24 h\" src=\"../include/info_green.png\"/>":"";
					echo ($result[$i]['fresh_auction'] == 1)?"<img title=\"Numai pentru utilizatorii fara licitatii castgate.\" src=\"../include/info_red.png\"/>":""; ?>
		   </td>
		</tr>
<?php
	}
?>
  <tr><td colspan="7" align="center"><?php echo $pagingLink; ?></td></tr>
<?php 
}
else {
?>
  <tr><td colspan="7" align="center">Nu au fost adaugate licitatii</td></tr>
<?php
}
?>
  <tr><td colspan="7">&nbsp;</td></tr>
 </table>
 <p>&nbsp;</p>
